package com.jjb.www.ui.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.core.content.ContextCompat;

import com.hjq.shape.layout.ShapeLinearLayout;
import com.hjq.shape.view.ShapeTextView;
import com.jjb.www.R;
import com.jjb.www.app.AppAdapter;
import com.jjb.www.http.api.AetNumberFillInfoApi;
import com.jjb.www.http.api.AetNumberFillInfoV2Api;

/**
 *    author : Android CRG
 *    github : https://github.com/getActivity/AndroidProject
 *    time   : 2018/11/05
 *    desc   : 可进行拷贝的副本
 */
public final class ComprehensiveV2Adapter2 extends AppAdapter<AetNumberFillInfoV2Api.Bean.QuestionSonListDTO.QuestionAnswerDTO> {
//    private int selPosition = -1;
    private OnChildListener mListener;
    public ComprehensiveV2Adapter2(Context context, OnChildListener listener) {
        super(context);
        this.mListener = listener;
    }


    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new ViewHolder();
    }

    private final class ViewHolder extends AppAdapter<?>.ViewHolder {
        private ShapeLinearLayout mLlItem;
        private ShapeTextView mTvTitle;



        private ViewHolder() {
            super(R.layout.item_sing_choice);
            mLlItem = findViewById(R.id.ll_item);
            mTvTitle = findViewById(R.id.tv_title);
        }

        @Override
        public void onBindView(int position) {
            AetNumberFillInfoV2Api.Bean.QuestionSonListDTO.QuestionAnswerDTO bean = getItem(position);
            mTvTitle.setText(bean.getOption());
            mLlItem.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    mListener.selectNumber(bean.getFaposition(),position);
                }
            });

            //试题类型 1单选 2判断 3多选 4综合题
            if (bean.isSelect()){
                mLlItem.getShapeDrawableBuilder()
                        .setSolidColor(ContextCompat.getColor(getContext(), R.color.color_EAF1FE))
                        .setStrokeColor(ContextCompat.getColor(getContext(), R.color.color_3675FE))
                        .setStrokeWidth(1)
                        .intoBackground();
            }else {
                mLlItem.getShapeDrawableBuilder()
                        .setSolidColor(ContextCompat.getColor(getContext(), R.color.white))
                        .setStrokeColor(ContextCompat.getColor(getContext(), R.color.color_DCDCDC))
                        .setStrokeWidth(1)
                        .intoBackground();

            }

        }
    }

    public interface OnChildListener{
        //题号父
        void selectNumber(int fatherPersion,int persion);
    }
//    public void setItemSel(int selPosition) {
//        this.selPosition = selPosition;
//        notifyDataSetChanged();
//    }
}